#include "ExitElement.hpp"

ExitElement::ExitElement(float x, float y, b2World* world) {
    this->impulseDirection = new b2Vec2(1.0f, 0.0f);

    b2BodyDef bodyDefinition;
    bodyDefinition.userData = this;
    bodyDefinition.position.Set(x, y);

    b2PolygonShape shape;
    shape.SetAsBox(0.8f, 1.0f);

    b2FixtureDef fixtureDefinition;
    fixtureDefinition.shape = &shape;
    fixtureDefinition.density = 0.0f;
    fixtureDefinition.isSensor = true;

    this->body = world->CreateBody(&bodyDefinition);
    this->body->CreateFixture(&fixtureDefinition);
}

ExitElement::~ExitElement() {
    delete this->impulseDirection;
}

bool ExitElement::isExit() {
    return true;
}

void ExitElement::setImpulseDirection(const b2Vec2 impulse) {
    this->impulseDirection->Set(impulse.x, impulse.y);
    this->impulseDirection->Normalize();
}
